package de.koller.balance.scene.planet;

import de.koller.aframe.gl.ATexture;
import de.koller.aframe.gl.Camera;
import de.koller.altitude.render.textures.GridTexture;
import de.koller.balance.render.BRenderExt;
import de.koller.oceanFramework.math.RVec3;
import org.lwjgl.opengl.GL11;

public class PlanetScene extends BRenderExt {

	private ATexture grid = new GridTexture();
	
	public final Camera camera = new Camera();
	//private final Quad quad = Quad.createZPlane( -10, 0, -20, 20, 20 ).setTextureLayout( 20, 20 );

	//private FormableCube cube = new FormableCube();
	
	float ty = 1;
	
	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		ty -= 0.05f * (elapsedTime/1000f);
	}
	
	private void initCamera() {
		commonUses.setUpPerspective();
		
		GL11.glPushMatrix();
		//camera.position.set( 0.8f, 1.8f, 1.8f );
		camera.position.set( 0, 0, 5 );
		camera.setLookAt( new RVec3( 0, 0, 0 ) );
		camera.up.set( 0, 1, 0 );
		camera.transformGL();
	}
	
	private void popCamera() {
		GL11.glPopMatrix();
	}
	
	private void renderCube() {
		GL11.glColor3f( 1, 1, 0 );
		grid.bindAnisotrophic();
		//cube.render();
	}

	@Override
	public void renderSzene() {
		initCamera();
		//renderCube();
		
		GL11.glColor3f( 1, 1, 1 );
		grid.bindAnisotrophic();
		GL11.glBegin( GL11.GL_QUADS );
			GL11.glTexCoord2f( 0, 0 );
			GL11.glVertex3f( -1,  1, 0 );
			
			GL11.glTexCoord2f( 0, 1 );
			GL11.glVertex3f( -1,  -1, 0 );
			
			GL11.glTexCoord2f( 1, 1 );
			GL11.glVertex3f( 1,  -1, 0 );
			
			GL11.glTexCoord2f( 1, 0 );
			GL11.glVertex3f( 1,   ty, 0 );
		GL11.glEnd();
		
		popCamera();
	}
	
}
